﻿#include <QApplication>
#include <QDebug>
#include <QMessageBox>
#include "DialogValid.h"
#include "ui_DialogValid.h"
#include "GlobalVar.h"
#include "Crypto.h"

DialogValid::DialogValid(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogValid)
{
    ui->setupUi(this);
}

DialogValid::~DialogValid()
{
    delete ui;
}

bool DialogValid::IsValid()
{
    ValidPw pw=GlobalVar::Instance().GetPw();
    return IsValidImp(pw.Password);
}

bool DialogValid::IsValidImp(QString key)
{
    return true;
    Crypto crypto("gs");
    QString formattedDate = QDateTime::currentDateTime().toString("yyyyMMdd");
    if(crypto.decrypt(key)==formattedDate)
    {
        return true;
    }
    else
    {
        return false;
    }
}

void DialogValid::on_buttonBox_accepted()
{
    QString key=ui->lineEdit->text();
    if(IsValidImp(key))
    {
        qDebug()<<__FUNCTION__<<__LINE__<<"密码验证正确!";
        QMessageBox::information(this,"提示","密码验证正确!");
        ValidPw pw;
        pw.Password=key;
        GlobalVar::Instance().SetPw(pw);
        this->accept();
    }
    else
    {
        QMessageBox::information(this,"提示","密码验证错误，程序退出!");
        this->reject();
    }
}

void DialogValid::closeEvent(QCloseEvent *event)
{

}
